#include<iostream>

using namespace std;

typedef long long ll;
const int N = 2e5 + 10;
ll arr1[N];
ll arr2[N];
int main()
{
	ll n, c; cin >> n >> c;
	ll x; ll sum = 0; ll le = 0;
	for (ll i = 0; i < n; i++)
	{
		cin >>x; 
		if (arr1[x] == 0)
		{
			arr2[le++] = x;
		}
		arr1[x]++;
	}
	
	for (ll i = 0; i < le; i++)
	{
		sum += arr1[c+arr2[i]]*arr1[arr2[i]];
	}

	cout << sum;

	return 0;
}